<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:awc="clr-namespace:Assergs.Windows.Controls"
    xmlns:aw="clr-namespace:Assergs.Windows"
    >

    <SolidColorBrush x:Key="ForegroundBrush" Color="{x:Static aw:GroupBoxPallet.Foreground}"/>
    <SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:GroupBoxPallet.NormalBorder}"/>
     
    <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>

    <Style x:Key="{x:Type GroupBox}" TargetType="{x:Type GroupBox}">
        <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupBox}">
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="6"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="6"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="6"/>
                        </Grid.RowDefinitions>
                        <Border CornerRadius="4"
                                Grid.Row="1"
                                Grid.RowSpan="3"
                                Grid.Column="0"
                                Grid.ColumnSpan="4"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="Transparent"
                                Background="{TemplateBinding Background}"/>
                        <Border x:Name="Header"
                                Padding="3,0,3,0"
                                Grid.Row="0"
                                Grid.RowSpan="2"
                                Grid.Column="1">
                            <ContentPresenter 
                                ContentSource="Header"
                                RecognizesAccessKey="True"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                TextElement.Foreground="{StaticResource ForegroundBrush}"/>
                        </Border>
                        <ContentPresenter Grid.Row="2"
                                Grid.Column="1"
                                Grid.ColumnSpan="2"
                                Margin="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        <Border CornerRadius="4"
                                Grid.Row="1"
                                Grid.RowSpan="3"
                                Grid.ColumnSpan="4"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}">
                            <Border.OpacityMask>
                                <MultiBinding Converter="{StaticResource BorderGapMaskConverter}"
                                              ConverterParameter="7">
                                    <Binding ElementName="Header"
                                             Path="ActualWidth"/>
                                    <Binding RelativeSource="{RelativeSource Self}"
                                             Path="ActualWidth"/>
                                    <Binding RelativeSource="{RelativeSource Self}"
                                             Path="ActualHeight"/>
                                </MultiBinding>
                            </Border.OpacityMask>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>